package dao;

import model.Service;
import net.sf.json.JSONArray;

import org.springframework.stereotype.Component;

import support.GridResult;
import dao.support.cache.Cache;
import dao.support.sql.SqlObject;

@Component
public class ServiceDao extends BaseDao{
	
	public String service_query(SqlObject so)
	{
		Object obj = this.querySQLRead(so.getSqlCount()).get(0).get("c");
		int total = Integer.parseInt(obj.toString());
		return new GridResult(so.getPage(), (total-1)/so.getRows()+1, total, this.querySQLRead(so.getSqlRows())).toString();
	}
	
	public void service_delete(String service_id)
	{
		Object []list = JSONArray.fromObject(service_id).toArray();
		for(Object obj : list)
		{
			String s = obj.toString();
			this.delete(Integer.parseInt(s), Service.class);
		}
	}
	
	public void service_add(Service service)
	{
		this.create(service);
	}
	
	public Service service_foundbyid(String service_id)
	{
		int id = Integer.parseInt(service_id);
		return (Service) super.loadById(id, Service.class);
	}
	
	public void service_update(Service service)
	{
	    this.update(service);
	}

}
